/**
 * Created by zhouli on 18/4/25
 * Email li.zhou@huilianyi.com
 * 显示部门树:无状态，只是显示
 */
import React from 'react';
import {messages} from "share/common";
import {Tree, Icon,Popover} from 'antd';
const TreeNode = Tree.TreeNode;
import 'styles/components/template/select-depment-by-role/dep-tree.scss';

class DepTree extends React.Component {
  constructor(props) {
    super(props);
    this.state = {}
  }
  componentWillMount() {
  }
  //渲染部门节点标题
  renderTreeNodesTitle = (item) => {
    return (<div className='node-title-wrap'>
      <Icon type="folder"/> &nbsp;
      <Popover placement="topLeft"
               content={`${item.name}${(item.status != 101 && this.props.showEnable ? messages('components.key775')/*(已停用)*/ : '')}`}
               overlayStyle={{maxWidth: 400}}>
            <span className='org-dep-node-title'>
            {`${item.name}${(item.status != 101 && this.props.showEnable ? messages('components.key775')/*(已停用)*/ : '')}`}
            </span>
      </Popover>
    </div>)
  }
  //渲染部门节点
  renderTreeNodes = (data) => {
    return data.map((item) => {
      if (item.childrenDepartment && item.childrenDepartment.length && item.childrenDepartment.length > 0) {
        return (
          <TreeNode
            title={
              this.renderTreeNodesTitle(item)
            }
            key={item.departmentOID}
            dataRef={item}
            className='org-dep-node'>
            {this.renderTreeNodes(item.childrenDepartment)}
          </TreeNode>
        );
      }
      return <TreeNode className='org-dep-node'
                       title={this.renderTreeNodesTitle(item)}
                       key={item.departmentOID}
                       dataRef={item}/>
    });
  }

  render() {
    const {multiple,selectedKeys,expandedKeys,autoExpandParent,onSelect,onExpand,treeData} = this.props;
    return (
      <div className="org-structure-role-tree">
        <Tree
          multiple={multiple}
          selectedKeys={selectedKeys}
          expandedKeys={expandedKeys}
          autoExpandParent={autoExpandParent}
          onSelect={onSelect}
          onExpand={onExpand}
        >
          {this.renderTreeNodes(treeData)}
        </Tree>
      </div>
    )
  }
}
DepTree.propTypes = {
  treeData: React.PropTypes.array.isRequired,//组织架构数据
  selectedKeys: React.PropTypes.array.isRequired,//被选择了的部门oid或者人oid
  expandedKeys: React.PropTypes.array.isRequired,//被展开了的部门
  autoExpandParent: React.PropTypes.bool.isRequired,
  onSelect: React.PropTypes.func.isRequired,// 点击激活某一个部门
  onExpand: React.PropTypes.func.isRequired,// 点击展开某一个部门
  showEnable:React.PropTypes.bool//是否显示禁用标识
};

DepTree.defaultProps = {};

export default DepTree;

